<template>
  <footer class="footer-menu">
    <el-menu
      :default-active="activeIndex"
      @select="handleSelect"
      class="el-menu-horizontal-demo"
      background-color="#add8e6"
      text-color="#000"
      active-text-color="#ff69b4"
    >
      <el-menu-item index="1">
        <el-icon><MessageBox /></el-icon>
        <template #title>
          <span class="menu-text">我的提问箱</span>
        </template>
      </el-menu-item>
      <el-menu-item index="2">
        <el-icon><Star /></el-icon>
        <span class="menu-text">加入的提问箱</span>
      </el-menu-item>
      <el-menu-item index="3">
        <el-icon><User /></el-icon>
        <span class="menu-text">个人</span>
      </el-menu-item>
      <el-menu-item index="4">
        <el-icon><Message /></el-icon>
        <span class="menu-text">消息</span>
      </el-menu-item>
      <el-menu-item index="5">
        <el-icon><Search /></el-icon>
        <span class="menu-text">搜索</span>
      </el-menu-item>
    </el-menu>
  </footer>
</template>

<script>
export default {
  name: "Footmenu",
  data() {
    return {
      activeIndex: "1",
    };
  },
  mounted() {
    this.setActiveIndexByRoute();
  },
  watch: {
    $route() {
      this.setActiveIndexByRoute();
    }
  },
  methods: {
    handleSelect(index) {
      this.activeIndex = index;
      const routes = {
        "1": "/mybox",
        "2": "/joinbox",
        "3": "/person",
        "4": "/message",
        "5": "/search"
      };
      this.$router.push(routes[index]);
    },
    setActiveIndexByRoute() {
      const pathToIndex = {
        "/mybox": "1",
        "/joinbox": "2",
        "/person": "3",
        "/message": "4",
        "/search": "5"
      };
      this.activeIndex = pathToIndex[this.$route.path] || "1";
    }
  }
};
</script>

<style scoped>
.footer-menu {
  position: absolute;
  bottom: 0;
  height: 8%;
  width: 1200px;
  background-color: #add8e6;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.el-menu-horizontal-demo {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: space-around;
  border: none;
}

.el-menu-item {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px !important;
  transition: all 0.3s ease;
}

.el-icon {
  font-size: 24px;
  margin-bottom: 2px;
  transition: all 0.3s ease;
}

.menu-text {
  font-size: 14px;
  margin-top: 2px;
  white-space: nowrap;
  transition: all 0.3s ease;
}

.el-menu-item:hover {
  transform: translateY(-2px);
  background-color: rgba(255, 255, 255, 0.1) !important;
}

.el-menu-item:hover .el-icon {
  transform: scale(1.1);
  color: #ff69b4;
}

.el-menu-item:hover .menu-text {
  color: #ff69b4;
}

.el-menu-item.is-active {
  border-bottom: none !important;
}

.el-menu-item.is-active .el-icon,
.el-menu-item.is-active .menu-text {
  color: #ff69b4;
}

</style>
